package com.cinema.entity.hall;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 放映厅实体类
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Hall implements Serializable {
    private static final long serialVersionUID = 1L;

    private String hallId;       // 放映厅ID
    private String hallName;     // 放映厅名称
    private int rowCount;        // 行数
    private int colCount;        // 列数
    private List<Seat> seats;    // 座位列表

    /**
     * 初始化放映厅（自动生成座位）
     */
    public Hall(String hallId, String hallName, int rowCount, int colCount) {
        this.hallId = hallId;
        this.hallName = hallName;
        this.rowCount = rowCount;
        this.colCount = colCount;
        this.seats = new ArrayList<>();

        // 生成座位（如1排1座、1排2座...）
        for (int i = 1; i <= rowCount; i++) {
            for (int j = 1; j <= colCount; j++) {
                seats.add(new Seat(i + "排" + j + "座", i, j, false, null));
            }
        }
    }

    /**
     * 根据座位ID查找座位
     */
    public Seat findSeatBySeatId(String seatId) {
        for (Seat seat : seats) {
            if (seat.getSeatId().equals(seatId)) {
                return seat;
            }
        }
        return null;
    }

    /**
     * 打印座位图
     */
    public void printSeatMap() {
        System.out.println("  列：1 2 3 4 5 6 7 8 9 10"); // 假设最多10列
        for (int i = 1; i <= rowCount; i++) {
            System.out.print("行" + i + "：");
            for (int j = 1; j <= colCount; j++) {
                Seat seat = findSeatBySeatId(i + "排" + j + "座");
                System.out.print(seat + " ");
            }
            System.out.println();
        }
        System.out.println("说明：■已售  □可售");
    }
}

